//
//  USMessageSetController.m
//  us
//
//  Created by karry on 2025/4/10.
//

#import "USMessageSetController.h"

@interface USMessageSetController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSArray *list;

@end

@implementation USMessageSetController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"消息设置";
    self.us_tableView.delegate = self;
    self.us_tableView.dataSource = self;
    
    [self setupData];
    
}

- (void)setupData{
    
    DTItem *pushNotification = [DTItem itemWithTitle:@"消息推送" image:nil tag:0 identifier:@"pushNotification" handle:nil];
    
    DTItem *pushSound = [DTItem itemWithTitle:@"新消息音效" image:nil tag:0 identifier:@"pushSound" handle:nil];
    DTItem *pushShake = [DTItem itemWithTitle:@"新消震动" image:nil tag:0 identifier:@"pushShake" handle:nil];
    
    self.list = @[pushNotification,pushSound,pushShake];
    

    
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.list.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [UITableViewCell us_defaultCell];
    
    DTItem *item = self.list[indexPath.row];
    
    cell.textLabel.text = item.title;
    
    
    if ([item.identifier isEqualToString:@"pushNotification"] ) {
        
        @weakify(self)
        [cell us_setAccessorySwitchisSelected:[[NSUserDefaults standardUserDefaults] boolForKey:USPrefKey_EnablePushNotification] action:^(BOOL selected) {
            @strongify(self)
            [[NSUserDefaults standardUserDefaults]setBool:selected forKey:USPrefKey_EnablePushNotification];
        }];
        
    }else if ([item.identifier isEqualToString:@"pushSound"] ) {
        
        @weakify(self)
        [cell us_setAccessorySwitchisSelected:[[NSUserDefaults standardUserDefaults] boolForKey:USPrefKey_EnablePushSound] action:^(BOOL selected) {
            @strongify(self)
            [[NSUserDefaults standardUserDefaults]setBool:selected forKey:USPrefKey_EnablePushSound];
        }];
        
    }else if ([item.identifier isEqualToString:@"pushShake"] ) {
        
        @weakify(self)
        [cell us_setAccessorySwitchisSelected:[[NSUserDefaults standardUserDefaults] boolForKey:USPrefKey_EnablePushVibration] action:^(BOOL selected) {
            @strongify(self)
            [[NSUserDefaults standardUserDefaults]setBool:selected forKey:USPrefKey_EnablePushVibration];
        }];
        
    }
   
    
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [UITableViewCell us_defaultCellRowHeight];
    
}

@end
